﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;

namespace SpriteSheetsCreator {
    public class ImageViewModel : INotifyPropertyChanged {
        private static int uniqueID = 0;

        #region Properties
        public int ImageId {
            get;
            private set;
        }

        private string _imageName;
        public string ImageName {
            get {
                return _imageName;
            }
            set {
                if (value != _imageName) {
                    _imageName = value;
                    NotifyPropertyChanged("ImageName");
                }
            }
        }

        private string _imageFullPath;
        public string ImageFullPath {
            get {
                return _imageFullPath;
            }
            set {
                if (value != _imageFullPath) {
                    _imageFullPath = value;
                    NotifyPropertyChanged("ImageFullPath");
                }
            }
        }

        private BitmapSource _imageBitmap;
        public BitmapSource ImageBitmap {
            get {
                return _imageBitmap;
            }
            set {
                if (value != _imageBitmap) {
                    _imageBitmap = value;
                    NotifyPropertyChanged("ImageBitmap");
                }
            }
        }
        #endregion

        public ImageViewModel() {
            ImageId = uniqueID++;
        }

        #region Property events (used for PropertyChanged behavior)
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName) {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler) {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

        #region Equality comparer
        public override bool Equals(System.Object obj) {
            // If parameter is null return false.
            if (obj == null) {
                return false;
            }

            // If parameter cannot be cast to Point return false.
            ImageViewModel p = obj as ImageViewModel;
            if ((System.Object)p == null) {
                return false;
            }

            // Return true if the fields match:
            return (ImageId == p.ImageId);
        }

        public bool Equals(ImageViewModel p) {
            // If parameter is null return false:
            if ((object)p == null) {
                return false;
            }

            // Return true if the fields match:
            return (ImageId == p.ImageId);
        }

        public override int GetHashCode() {
            return ImageId;
        }
        #endregion
    }
}